<?php
class InfectionsController extends AppController {

	var $name = 'Infections';

	function index() {
		$this->Infection->recursive = 0;
		$this->set('infections', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid infection', true));
			$this->redirect($this->referer());
		}
		$this->set('infection', $this->Infection->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Infection->create();
			if ($this->Infection->save($this->data)) {
				$this->Session->setFlash(__('The infection has been saved', true));
				$this->redirect(array('controller' => 'audits', 'action' => 'view/'.$this->data['Infection']['audit_id']));
			} else {
				$this->Session->setFlash(__('The infection could not be saved. Please, try again.', true));
			}
		}
		$audits = $this->Infection->Audit->find('list');
		$this->set(compact('audits'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid infection', true));
			$this->redirect($this->referer());
		}
		if (!empty($this->data)) {
			if ($this->Infection->save($this->data)) {
				$this->Session->setFlash(__('The infection has been saved', true));
				$this->redirect(array('controller' => 'audits', 'action' => 'view/'.$this->data['Infection']['audit_id']));
			} else {
				$this->Session->setFlash(__('The infection could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Infection->read(null, $id);
		}
		$audits = $this->Infection->Audit->find('list');
		$this->set(compact('audits'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for infection', true));
			$this->redirect($this->referer());
		}
		if ($this->Infection->delete($id)) {
			$this->Session->setFlash(__('Infection deleted', true));
			$this->redirect($this->referer());
		}
		$this->Session->setFlash(__('Infection was not deleted', true));
		$this->redirect($this->referer());
	}
}
?>